import { createRouter, createWebHashHistory } from 'vue-router'
// 学习vue
import Study from '../views/Study.vue'
import Studya from '../views/Studya.vue'

// 登陆
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'
// 后台 - 首页
import Index from '../views/Index.vue'
// 学员管理
import Student from '../views/student/Student.vue'
// 班级管理
import ClassMan from '../views/classMan/ClassMan.vue'
// 考勤管理
import CheckWork from '../views/checkWork/CheckWork.vue'
// 课程汇总
import Course from '../views/course/Course.vue'
// 学校动态
import Dynamic from '../views/school/Dynamic.vue'  // 动态管理
import WheelImg from '../views/school/WheelImg.vue'  // 轮播图
import SchoolInfo from '../views/school/SchoolInfo.vue'  // 学校介绍
import Contact from '../views/school/Contact.vue'  // 联系方式
import Compus from '../views/school/Compus.vue'  // 校区管理
// 其他设置
import ClassGod from '../views/other/ClassGod.vue'  // 课程管理
import ClassRoomGod from '../views/other/ClassRoomGod.vue'  // 教室管理
import ThecherGod from '../views/other/ThecherGod.vue'  // 教师管理
import UserGod from '../views/other/UserGod.vue'  // 账号管理

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
  	name: 'Login',
  	component: Login
  },
	{
    path: '/study',
		name: 'Study',
		component: Study
  },
	{
    path: '/studya',
		name: 'Studya',
		component: Studya
  },
  {
    path: '/home',
		component: Home,
		redirect: '/index',
		children:[
			{path: '/index', name: 'Index', component: Index},
			{path: '/student', name: 'Student', component: Student},
			{path: '/classMan', name: 'ClassMan', component: ClassMan},
			{path: '/checkWork', name: 'CheckWork', component: CheckWork},
			{path: '/course', name: 'Course', component: Course},
			
			{path: '/dynamic', name: 'Dynamic', component: Dynamic},
			{path: '/wheelImg', name: 'WheelImg', component: WheelImg},
			{path: '/schoolInfo', name: 'SchoolInfo', component: SchoolInfo},
			{path: '/contact', name: 'Contact', component: Contact},
			{path: '/compus', name: 'Compus', component: Compus},
			
			{path: '/classGod', name: 'ClassGod', component: ClassGod},
			{path: '/classRoomGod', name: 'ClassRoomGod', component: ClassRoomGod},
			{path: '/thecherGod', name: 'ThecherGod', component: ThecherGod},
			{path: '/userGod', name: 'UserGod', component: UserGod},
		]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {
	if(to.path == '/login') return next();
	const token = window.sessionStorage.getItem('token')
	if(token){
		return next();
	}
	next('/login');
})

export default router
